package com.gitee.llj.api.controller.sys;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gitee.llj.api.service.sys.ISysModuleService;
import com.gitee.llj.entity.sys.SysModule;
import com.gitee.llj.tools.base.BaseController;
import com.gitee.llj.tools.base.ResultModel;
import com.gitee.llj.tools.base.ResultStatus;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>模块controller</p>
 *
 * @Author llj
 * @Date 2018/5/10
 */
@RestController
@RequestMapping("/api/sysmodule")
public class ApiSysModuleController extends BaseController{
    @Resource
    private ISysModuleService sysModuleService;

    /**
     * 获得所有模块(菜单)
     * 包含子模块
     * @return
     */
    @RequestMapping("all")
    public ResultModel getAllSysModules(){
        return  ResultModel.ok(sysModuleService.selectAllSysModules());
    }

    /**
     * 获得用户对应模块
     * @param userId
     * @return
     */
    @RequestMapping("get-by-user")
    public ResultModel getSysModuelsByUser(String userId){
        if (StringUtils.isBlank(userId)){return new ResultModel(ResultStatus.FAIL.getSuccess(),"用户ID不能为空"); }
        return ResultModel.ok(sysModuleService.selectSysModuelsByUser(userId));
    }

    /**
     * 获得用户权限
     * @param userId
     * @return
     */
    @RequestMapping("permission")
    public ResultModel getPermissionByUser(@RequestParam("userId") String userId){
        if (StringUtils.isBlank(userId)){return new ResultModel(ResultStatus.FAIL.getSuccess(),"用户ID不能为空"); }
        return ResultModel.ok(sysModuleService.selectPermissionByUser(userId));
    }
}
